﻿using System;
using System.Diagnostics;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;
using TI_BLE_HCI_ClientLib.HCIEvents;
using Utilities;

namespace TI_BLE_HCI_ClientLib.HCIParsers
{
    public static partial class HCIEventParser
    {
        private static HCIEvent parseHCI_LE_ExtEvent_GAP_Device_Information(byte parsLen, byte[] buffer)
        {
            if (parsLen < 11) throw new ArgumentException("parseHCI_LE_ExtEvent_GAP_DeviceInformation Parameters Length < 11");
            byte bufIdx = 4;

            HCIVendorSpecificEventHostErrorCode status = (HCIVendorSpecificEventHostErrorCode)parseByteParameter(buffer, ref bufIdx);
            TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Device_Information.EventTypeEnum eventType = (TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Device_Information.EventTypeEnum)parseByteParameter(buffer, ref bufIdx);
            TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Device_Information.AddrTypeEnum addrType = (TI_BLE_HCI_ClientLib.HCIEvents.HCIEvent_GAP_Device_Information.AddrTypeEnum)parseByteParameter(buffer, ref bufIdx);
            byte[] addr = parseBufferParameter(6, buffer, ref bufIdx);
            sbyte rssi = parseSByteParameter(buffer, ref bufIdx);

            byte dataLen = parseByteParameter(buffer, ref bufIdx);
            byte[] dataField = parseBufferParameter(dataLen, buffer, ref bufIdx);

            var hciEvent = new HCIEvent_GAP_Device_Information(status, eventType, addrType, addr, rssi, dataField);

            return hciEvent;
        }
    }
}
